package com.hjh.mode.composite;

import java.util.ArrayList;
import java.util.List;

public class Composite  extends WindowComponent {

    private List<WindowComponent> childComponents = new ArrayList<>();
    public  Composite(String name){
        super();
        this.name = name;
    }

    public void addChild(WindowComponent child){
        if(child   != null){
            childComponents.add(child);
        }
    }

    @Override
    public void print() {
        System.out.println("print "+name);

        for (WindowComponent childComponent : childComponents) {
            childComponent.print();
        }
    }
}
